// components/exam-question/exam-question.ts
Component({
  options: {
    addGlobalClass: true,
  },
  properties: {
    question: {
      type: Object,
      value: {},
      observer: function(newVal: any) {
        // 当question数据变化时，解析其中的内容和图片
        if (newVal && (newVal.content || newVal.answerAnalysis)) {
          const parsedContent = getApp().globalData.examUtils.parseContentWithImages(newVal.content || '');
          const parsedAnalysis = getApp().globalData.examUtils.parseContentWithImages(newVal.answerAnalysis || '');
          
          this.setData({
            'question.parsedContent': parsedContent,
            'question.parsedAnalysis': parsedAnalysis
          });
        }
      }
    },
    index: {
      type: Number,
      value: 0
    },
    // 选项样式映射
    optionClassMap: {
      type: Object,
      value: {}
    }
  },

  data: {

  },

  lifetimes: {
    attached() {
      // 组件实例进入页面节点树时执行
    },
  },

  methods: {
    // 选择选项
    selectOption(e: any) {
      const { option } = e.currentTarget.dataset;
      this.triggerEvent('selectoption', { option, index: this.data.index });
    },

    // 切换解析显示
    toggleExplanation() {
      this.triggerEvent('toggleexplanation', { index: this.data.index });
    },

    // // 收藏题目
    // onFavorite() {
    //   this.triggerEvent('favorite', {
    //     questionId: this.data.question.questionId,
    //     index: this.data.index
    //   });
    // },
    //
    // // 报告题目问题
    // onReportIssue() {
    //   this.triggerEvent('reportissue', {
    //     questionId: this.data.question.questionId,
    //     index: this.data.index
    //   });
    // }
  }
})